package com.mayuhao.adminmanage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mayuhao.adminmanage.entity.CssAdmin;
import com.mayuhao.adminmanage.service.ICssAdminService;
import com.mayuhao.adminmanage.util.Result;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 马宇豪
 * @since 2022-11-14
 */
@RestController
//@RequestMapping("/css-admin")
public class CssAdminController {
    @Resource
    private ICssAdminService adminService;

    /**
     * @return com.baomidou.mybatisplus.extension.plugins.pagination.Page<CssClassVO>
     * @description 请修改方法描述
     * @methodName findPage
     * @params [pageNum, pageSize, searchId, searchName]
     * @paramType [java.lang.Integer, java.lang.Integer, java.lang.String, java.lang.String]
     * @author 马宇豪
     * @date 2022/11/14 0014 下午 12:59
     * Cssl 1757442521@qq.com
     **/
    @GetMapping("/findpage")
    public Page<CssAdmin> findPage(@RequestParam(defaultValue = "1") Integer pageNum,
                                   @RequestParam(defaultValue = "7") Integer pageSize,
                                   @RequestParam(defaultValue = "") String searchId,
                                   @RequestParam(defaultValue = "") String searchName) {
        return adminService.findPage(pageNum, pageSize, searchId, searchName);
    }


    /**
     * @return com.mayuhao.adminmanage.util.Result
     * @description 请修改方法描述
     * @methodName saveAdmin
     * @params [cssAdmin]
     * @paramType [com.mayuhao.adminmanage.entity.CssAdmin]
     * @author 马宇豪
     * @date 2022/11/14 0014 下午 1:36
     * @email 1757442521@qq.com
     **/
    @PostMapping("/save")
    public Result saveAdmin(@RequestBody CssAdmin cssAdmin) {
        return new Result(true, "ok", adminService.save(cssAdmin));
    }

    /**
     * @return com.mayuhao.adminmanage.util.Result
     * @description 请修改方法描述
     * @methodName deleteAdmin
     * @params [id]
     * @paramType [java.lang.Integer]
     * @author 马宇豪
     * @date 2022/11/14 0014 下午 1:37
     * @email 1757442521@qq.com
     **/
    @DeleteMapping("/delsingle/{id}")
    public Result deleteAdmin(@PathVariable Integer id) {
        return new Result(true, "ok", adminService.removeById(id));
    }

    /**
     * @return com.mayuhao.adminmanage.util.Result
     * @description 请修改方法描述
     * @methodName updateAdmin
     * @params [cssAdmin]
     * @paramType [com.mayuhao.adminmanage.entity.CssAdmin]
     * @author 马宇豪
     * @date 2022/11/14 0014 下午 1:45
     * @email 1757442521@qq.com
     **/
    @PutMapping("/update")
    public Result updateAdmin(@RequestBody CssAdmin cssAdmin) {
        return new Result(true, "ok", adminService.updateById(cssAdmin));
    }

    @DeleteMapping("/delbatch/{ids}")
    public boolean deleteAdmin(@PathVariable List ids) {
        return adminService.removeBatchByIds(ids);
    }


    @GetMapping("/export")
    public void export(HttpServletResponse response) throws IOException {

        adminService.export(response);
    }

    @PostMapping("/import")
    public void imp(MultipartFile file) throws Exception {
        adminService.imp(file);
    }


}
